package com.qdlc.p2p.dal.model;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import com.qdlc.p2p.common.constant.GeneralAccountType;
import com.qdlc.p2p.common.util.DateUtil;
import com.qdlc.p2p.common.util.StringUtil;
import com.qdlc.p2p.dal.common.SystemConfigHelper;
import com.qdlc.p2p.dal.common.SystemConfigHelper.Nid;
import com.qdlc.p2p.dal.dto.AccountLog;
import com.qdlc.p2p.dal.util.SystemConfigs;

/**
 * 资金记录Model
 *
 * @author xx
 * @version 2.0
 * @since 2014年3月27日
 */
public class AccountLogModel extends AccountLog {

    /**
     * 当前页面
     */
    private int page;

    /**
     * 显示数量
     */
    private int rows;
    /**
     * 资金记录类型名称
     */
    private String typeName;
    /**
     * 交易方
     */
    private String toUserName;
    /**
     * 开始日期
     **/
    private String startTime;
    /**
     * 结束日期
     **/
    private String endTime;

    private Date startDate;
    private Date endDate;

    /**
     * 日期范围：0：全部，1：最近七天 2：最近一个月 3：最近两个月，4 最近三个月
     **/
    private int time;
    /**
     * 用户名
     */
    private String userName;
    /**
     * 标名称
     */
    private String borrowName;
    /**
     * 资金类型--取该名字为了前端统一
     */
    private String status;

    /**
     * 条件查询
     */
    private String searchName;

    /**
     * 查询现在时间
     */
    private Date nowTime;

    /**
     * 查询回滚时间
     */
    private Date rollDay;

    /**
     * 真实姓名
     */
    private String realName;

    public static AccountLogModel instance(AccountLog accountLog) {
        AccountLogModel accountLogModel = new AccountLogModel();
        BeanUtils.copyProperties(accountLog, accountLogModel);
        return accountLogModel;
    }

    public AccountLog prototype() {
        AccountLog accountLog = new AccountLog();
        BeanUtils.copyProperties(this, accountLog);
        return accountLog;
    }

    /**
     * 获取（隐藏一定位数的）交易对方
     *
     * @return
     */
    public String getHideToUserName() {
        // Long adminId = SystemConfigHelper.getLongValue(Nid.ADMIN_ACCOUNT);
        // 平台
        String hideName = getToUserId() == GeneralAccountType.PLATFORM ? SystemConfigs.WEB_NAME : "";
        // 托管
        hideName = StringUtil.isEmpty(hideName) && getToUserId() == GeneralAccountType.IDC ? "托管" : hideName;
        // 自己
        hideName = StringUtil.isEmpty(hideName) && getUserId() == getToUserId() ? "-" : hideName;
        // 投资人
        hideName = StringUtil.isEmpty(hideName) && getToUserId() == GeneralAccountType.INVESTOR ? "投资人" : hideName;
        // 实际人
        hideName = StringUtil.isEmpty(hideName) ? StringUtil.hideStr(toUserName, 1, toUserName.length() - 1) : hideName;
        return hideName;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public Date getStartDate() {
        return startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public Date getNowTime() {
        return nowTime;
    }

    public void setNowTime(Date nowTime) {
        this.nowTime = nowTime;
    }

    public void setStartDateAndEndDate() {
        if (StringUtils.isNotBlank(startTime)) {
            startDate = DateUtil.valueOf(startTime + " 00:00:00");
        }
        if (StringUtils.isNotBlank(endTime)) {
            endDate = DateUtil.valueOf(endTime + " 23:59:59");
        }
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getBorrowName() {
        return borrowName;
    }

    public void setBorrowName(String borrowName) {
        this.borrowName = borrowName;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public String getSearchName() {
        return searchName;
    }

    public void setSearchName(String searchName) {
        this.searchName = searchName;
    }

    public Date getRollDay() {
        return rollDay;
    }

    public void setRollDay(Date rollDay) {
        this.rollDay = rollDay;
    }

    /**
     * 账户总额转换为字符串防止数值过大变成科学计数法显示
     *
     * @return
     */
    public String getTotalString() {
        return new BigDecimal(Double.toString(getTotal())).toPlainString();
    }

    /**
     * 操作金额转换为字符串防止数值过大变成科学计数法显示
     *
     * @return
     */
    public String getMoneyString() {
        return new BigDecimal(Double.toString(getMoney())).toPlainString();
    }

    /**
     * 可用金额转换为字符串防止数值过大变成科学计数法显示
     *
     * @return
     */
    public String getUseMoneyString() {
        return new BigDecimal(Double.toString(getUseMoney())).toPlainString();
    }

    /**
     * 冻结金额转换为字符串防止数值过大变成科学计数法显示
     *
     * @return
     */

    public String getNoUseMoneyString() {
        return new BigDecimal(Double.toString(getNoUseMoney())).toPlainString();
    }

    /**
     * 待收金额转换为字符串防止数值过大变成科学计数法显示
     *
     * @return
     */
    public String getCollectionString() {
        return new BigDecimal(Double.toString(getCollection())).toPlainString();
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }
}
